package com.eastfair.auth.api;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.annotation.annotation.base.BaseControllerInfo;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.auth.dto.*;
import com.eastfair.auth.entity.Organization;
import com.eastfair.auth.entity.Role;
import com.eastfair.auth.entity.UserAccount;
import com.eastfair.auth.entity.UserOrganization;
import com.eastfair.auth.exceptioncode.AuthServiceExceptionCode;
import com.eastfair.auth.hystrix.AuthApiFallback;
import com.eastfair.auth.hystrix.UserAccountApiFallback;
import com.eastfair.auth.vo.ResourceOrganizationVo;
import com.eastfair.auth.vo.RoleVo;
import com.eastfair.auth.vo.UserAccountVo;
import com.eastfair.boot.request.PageParams;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.BizException;
import com.eastfair.el.ElParam;
import com.eastfair.projectcore.enumeration.DataIsolationSystemSceneEnum;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * auth feign接口
 *
 * @Author ligang
 * @Date 2021/7/16 16:41
 */
@FeignClient(name = "auth/userAccount", fallback = UserAccountApiFallback.class)
public interface UserAccountServiceFeign {

    /**
     * 获取用户账户
     *
     * @param userId 用户id
     * @return
     */
    @GetMapping("/getById")
    R<UserAccount> get(@RequestParam("userId") Long userId);

    /**
     * 获取用户账户名称
     *
     * @param userId 用户id
     * @return
     */
    @GetMapping("/getNameById")
    R<String> getName(@RequestParam("userId") Long userId);


    /**
     * 批量查询用户简单信息
     *
     * @param userAccountDto userIds 账户用户id集合
     * @return
     */
    @PostMapping("/querySimpleByIds")
    R<List<UserAccountVo>> querySimpleByIds(@RequestBody UserAccountDto userAccountDto);


    /**
     * 给其他项目创建管理员
     *
     * @param userAccountDto 用户新增实体
     * @return
     */
    @ApiOperation(value = "给其他项目创建管理员", notes = "给其他项目创建管理员")
    @PostMapping("/addAdminUser")
    R<UserAccountVo> addAdminUser(@RequestBody UserAccountDto userAccountDto);

    /**
     * 根据邮箱和手机号查询用户信息
     *
     * @param mobile 用户id
     * @param email  手机号
     * @return
     */
    @ApiOperation(value = "根据邮箱和手机号查询用户信息", notes = "根据邮箱和手机号查询用户信息")
    @GetMapping("/queryOfPhoneOrEmail")
    R<UserAccount> queryOfPhoneOrEmail(@RequestParam("mobile") String mobile, @RequestParam("email") String email);


    @ApiOperation(value = "注册", notes = "注册")
    @PostMapping("/register")
    R<UserAccountVo> register(@RequestBody UserAccountDto userAccountDto);


    @ApiOperation(value = "根据邮箱和手机号查询用户信息", notes = "根据邮箱和手机号查询用户信息")
    @GetMapping("/test")
    R<String> test();


    /**
     * 成为展商，观众
     *
     * @param userAccountDto
     * @return
     */
    @ApiOperation(value = "成为展商，观众", notes = "成为展商，观众")
    @PostMapping("/initRole")
    R<UserAccountVo> initRole(@RequestBody UserAccountDto userAccountDto);

    /**
     * 检验是否有权限
     *
     * @param userId
     * @param permission
     * @return
     */
    @ApiOperation(value = "检验是否有权限", notes = "检验是否有权限")
    @GetMapping("/isPermission")
    R<Boolean> isPermission(@RequestParam("userId") Long userId, @RequestParam("permission") String[] permission, @RequestParam("classPermission") String[] classPermission);


    /**
     * 修改关联信息（观众id，展商id，公司id）
     *
     * @param userAccountDto
     * @return
     */
    @ApiOperation(value = "修改关联信息", notes = "修改关联信息")
    @PostMapping("/updateCorrelationById")
    R<Boolean> updateCorrelationById(@RequestBody UserAccountDto userAccountDto);


    /**
     * 添加公司用户
     *
     * @param userAccountDto 用户新增实体
     * @return
     */
    @ApiOperation(value = "添加公司用户", notes = "添加公司用户")
    @PostMapping("/saveCompanyUser")
    R<UserAccountVo> saveCompanyUser(@RequestBody UserAccountDto userAccountDto);


    /**
     * 修改用户信息
     *
     * @param userAccountDto
     * @return
     */
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
    @PutMapping("/updateById")
    R<Boolean> updateById(@RequestBody UserAccountDto userAccountDto);


    /**
     * 查询用户简单信息
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询用户信息", notes = "查询用户信息")
    @GetMapping("/findSimpleById")
    R<UserAccountVo> findSimpleById(@RequestParam("userId") Long userId);


    /**
     * 查询用户权限
     *
     * @param elParam
     * @return
     */
    @ApiOperation(value = "查询用户权限", notes = "查询用户权限")
    @PostMapping("/getPermissionOfUserId")
    R<List<String>> getPermissionOfUserId(@RequestBody ElParam elParam);

    /**
     * 查询用户角色
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询用户角色", notes = "查询用户角色")
    @GetMapping("/getRoleOfUserId")
    R<List<RoleVo>> getRoleOfUserId(@RequestParam("userId") Long userId);

    /**
     * 用户注册到子系统
     *
     * @param userAccountDto 用户新增实体
     * @return
     */
    @ApiOperation(value = "用户注册到子系统", notes = "用户注册到子系统")
    @PostMapping("/registerSubSystemUser")
    R<UserAccountVo> registerSubSystemUser(@RequestBody UserAccountDto userAccountDto);


    /**
     * 执行查询
     * <p>
     * 可以覆盖后重写查询逻辑
     *
     * @param params 分页参数
     * @return
     */
    @ApiOperation(value = "分页列表查询")
    @PostMapping(value = "/pageVo")
    R<IPage<UserAccountVo>> pageVo(@RequestBody PageParams<UserAccountDto> params);


    /**
     * 批量查询用户ID
     *
     * @param userAccountDto
     * @return
     */
    @PostMapping("/queryIds")
    R<List<Long>> queryIds(@RequestBody UserAccountDto userAccountDto);

    /**
     * 批量查询用户手机号
     *
     * @param userAccountDto
     * @return
     */
    @PostMapping("/queryMobiles")
    R<Map<Long, String>> queryMobiles(@RequestBody UserAccountDto userAccountDto);

    /**
     * 注册服务商功能
     *
     * @param registerDTO
     * @return
     */
    @ApiOperation(value = "注册服务商功能", notes = "注册服务商功能")
    @PostMapping("/registerServiceProvider")
    R registerServiceProvider(@RequestBody RegisterDTO registerDTO);

    /**
     * 获取token
     *
     * @param userAccountDto
     * @return
     */
    @ApiOperation(value = "获取token", notes = "获取token")
    @PostMapping("/getToken")
    R<String> getToken(@RequestBody UserAccountDto userAccountDto);


    /**
     * 查询节点的负责人信息
     *
     * @param organizationDto 组织Dto
     * @return
     */
    @ApiOperation(value = "查询节点的负责人信息", notes = "查询节点的用户信息")
    @PostMapping("/findAllLeaderUserOfOrg")
    R<List<UserAccountVo>> findAllLeaderUserOfOrg(@RequestBody OrganizationDTO organizationDto);

    /**
     * 查询用户接口权限
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询用户接口权限", notes = "查询用户接口权限")
    @GetMapping("/getIntegerOfUserId")
    R<List<String>> getPermissionOfUserId(@RequestParam("userId") Long userId);

    /**
     * 加载用户接口权限信息
     *
     * @param
     * @return
     */
    @ApiOperation(value = "加载用户接口权限信息", notes = "加载用户接口权限信息")
    @GetMapping("/loadUserInterface")
    R loadUserInterface(@RequestParam("userId") Long userId);




}
